interface s属性face {
    s数值: number,
    c层数: number,
    代号: number,
    k可点击: number
}
import { _decorator, Animation, Component, director, EventTouch, find, instantiate, log, Node, Tween, tween, v3 } from 'cc';
import { tongyongTS } from '../tongyongTS/tongyongTS';
import { mlgmDTSJ } from './mlgmDTSJ';
import { weixinapi } from '../tongyongTS/weixinAIP';
const { ccclass, property } = _decorator;

@ccclass('malegemaTS')
export class malegemaTS extends Component {
    readonly z总类型 = [636, 1, 2, 3, 11, 12, 13, 16, 17, 18, 22, 23, 24, 5, 6, 7, 26, 27, 28, 9, 131, 232, 333, 434]
    readonly g过关奖励金币 = 200
    readonly d点击直接展示广告 = false
    readonly d道具只能使用一次 = false

    HC_MLGM_chuangguangshu = 0
    HC_qian = 0
    c测试中 = false

    z子牌 = null
    p牌组 = null
    ty: tongyongTS

    c初始x = -297.5
    c初始y = -160
    j间隔距离x = 35
    j间隔距离y = 50


    z左组初始x = -305
    z左组初始y = -310
    j间隔距离小 = 20


    z总行数 = 11
    z总列数 = 18

    t填充类型: number[] = []
    z总填充组: number[] = []
    cs层数据组: number[][] = []
    cs层节点组: Node[][] = []

    x小层节点组: Node[][] = [[null, null]]

    s属性: s属性face = {
        s数值: 0,
        c层数: 0,
        代号: 0,
        k可点击: 1
    }


    g关卡总数 = 0
    d当前消除数 = 0


    h盒子节点: Node[] = []
    h盒子总数 = 6



    ceshi() {
        this.s胜利执行()
    }


    ceshi2() {
        director.loadScene('malegema')
    }

    ceshi3() {
        log(mlgmDTSJ.sj)

    }
    protected onLoad(): void {
        this.ty = find('通用管理').getComponent(tongyongTS)
        this.z子牌 = this.ty.find查找('Canvas/克隆主/牌1')
        this.p牌组 = this.ty.find查找('Canvas/牌组')

        //缓存
        this.HC_MLGM_chuangguangshu = JSON.parse(localStorage.getItem('HC_MLGM_chuangguangshu'))
        this.HC_qian = JSON.parse(localStorage.getItem('HC_qian'))

    }

    start() {
        this.生成数据数组()
        this.s设计填充()

        this.K开局动画()

        let v = v3(-135, 605)
    }

    j教学中 = false
    K开局动画() {
        let gn = this.ty.find查找('Canvas/上方显示组/第几关')
        gn.setPosition(0, 0)

        //光环转动
        let n = find('Canvas/上方显示组/进度/guanghuan')
        let t = tween(n).by(5, { angle: 360 })
        tween(n).repeatForever(t).start()

        let wzn = this.ty.find查找('Canvas/上方显示组/第几关/关卡显示/修改文字')
        let wz = this.HC_MLGM_chuangguangshu + 1 + ''
        this.ty.x修改文字(wzn, wz)

        wzn = this.ty.find查找('Canvas/上方显示组/金币显示/修改文字')
        wz = this.HC_qian + ''
        this.ty.x修改文字(wzn, wz)

        //教学
        if (this.HC_MLGM_chuangguangshu == 0) {
            let jxn = this.ty.find查找('Canvas/教学组')
            jxn.active = true

            let szn = this.ty.find查找('Canvas/教学组/shouzhi1')
            let t = tween(szn).by(0.5, { position: v3(10, -10) }).by(0.5, { position: v3(-10, 10) })
            tween(szn).repeatForever(t).start()
            this.j教学中 = true

            let gn = this.ty.find查找('Canvas/上方显示组/第几关/弹出显示组')
            gn.setPosition(5000, 5000)

            let gxn = this.ty.find查找('Canvas/上方显示组/第几关/关卡显示')
            gxn.setPosition(-135, 605)
        } else {


            let sywz = this.ty.find查找('Canvas/上方显示组/第几关/弹出显示组/显示组/10fangkua/剩余障碍_文字')
            let wz = '剩余麻将：' + this.g关卡总数
            this.ty.x修改文字(sywz, wz)

            let ZN = this.ty.find查找('Canvas/上方显示组/第几关/弹出显示组/遮挡触发')
            ZN.on(Node.EventType.TOUCH_START, this.点击开始, this)
        }



    }

    点击开始() {
        this.ty.z震动执行()
        let gn = this.ty.find查找('Canvas/上方显示组/第几关/弹出显示组')
        gn.setPosition(5000, 5000)

        let gxn = this.ty.find查找('Canvas/上方显示组/第几关/关卡显示')
        let v = v3(-135, 605)
        tween(gxn).to(0.5, { position: v }).start()
    }

    b必看广告关卡 = false
    生成数据数组() {
        let dts = this.HC_MLGM_chuangguangshu
        if (dts == 2 || dts == 8 || dts == 12 || dts > mlgmDTSJ.sj.d地图.length - 1) {
            this.b必看广告关卡 = true

        }

        if (this.b必看广告关卡) {
            log('本关必看广告')
            let a = JSON.stringify(mlgmDTSJ.sj.b必看广告地图)
            let b: number[][] = JSON.parse(a)
            b.forEach((e) => {
                this.cs层数据组.push(e)
            })
        }

        if (dts > mlgmDTSJ.sj.d地图.length - 1) {
            let sj = this.ty.Rand(1, 2)                //1/3概率随机地图
            if (sj == 1) {
                log('随机地图')
                let b2 = this.s随机地图(this.ty.Rand(3, 8), this.ty.Rand(12, 30))
                b2.forEach((e) => {
                    this.cs层数据组.push(e)
                })
            } else {
                let sjdts = this.ty.Rand(1, mlgmDTSJ.sj.d地图.length - 1)
                log('选择地图' + sjdts)
                let a = JSON.stringify(mlgmDTSJ.sj.d地图[sjdts])
                let b: number[][] = JSON.parse(a)
                b.forEach((e) => {
                    this.cs层数据组.push(e)
                })
            }
        } else {
            let a = JSON.stringify(mlgmDTSJ.sj.d地图[dts])
            let b: number[][] = JSON.parse(a)
            b.forEach((e) => {
                this.cs层数据组.push(e)
            })
        }


        //生成数据数组
        for (let i = 0; i < this.cs层数据组.length; i++) {
            let sz = []
            for (let hh = 0; hh < this.z总行数; hh++) {
                for (let lh = 0; lh < this.z总列数; lh++) {
                    sz.push(null)
                }
            }
            this.cs层节点组.push(sz)
        }

    }

    s设计填充() {
        this.t填充难度(this.HC_MLGM_chuangguangshu)

        //最后修改剩余显示
        let ns = this.ty.find查找('Canvas/上方显示组/进度/yuanhuawen/Label')
        let wz = this.g关卡总数 + ''
        this.ty.x修改文字(ns, wz)
    }

    s随机地图(c层数, t填充数) {
        let dtsc: number[][] = []
        let cengshu = c层数 - 1
        let zt = 0

        for (let i = 0; i < cengshu; i++) {
            if (zt == 0) {
                zt = 1
            } else {
                zt = 0
            }

            let zdt1 = [0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1]
            let zdt2 = [-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0]

            let daihao = 0
            let dhsz = []
            let zst = []
            if (zt == 0) {
                zst = Array.from(zdt1)
            } else {
                zst = Array.from(zdt2)
            }
            zst.forEach((e) => {
                if (e == 0) {
                    dhsz.push(daihao)
                }
                daihao++
            })  //最大每层54个方块

            let tianchongsu = t填充数      //可修改
            let tc = 54 - tianchongsu
            if (tc < 1) {
                tc = 1
            }
            this.ty.s随机打乱(dhsz)
            let lssc1 = Array.from(zst)
            for (let k = 0; k < tc; k++) {
                lssc1[dhsz[k]] = -1
            }
            dtsc.push(lssc1)

        }

        return dtsc
    }


    n难度类型 = [
        [131, 22, 23, 24, 232, 333, 15, 16, 17]
        ,
        [131, 1, 2, 3, 232, 11, 12, 13, 333, 15, 16, 17]
        ,
        [131, 1, 2, 3, 232, 11, 12, 13, 333, 15, 16, 17, 434, 22, 23, 24]
        ,
        [131, 1, 2, 3, 232, 11, 12, 13, 333, 15, 16, 17, 434, 22, 23, 24, 535, 5, 6, 7]
        ,
        [131, 1, 2, 3, 232, 11, 12, 13, 333, 15, 16, 17, 434, 22, 23, 24, 535, 5, 6, 7, 636]
        ,
        [131, 1, 2, 3, 232, 11, 12, 13, 333, 15, 16, 17, 434, 22, 23, 24, 535, 5, 6, 7, 636, 26, 27, 28]
        ,
        [131, 1, 2, 3, 232, 11, 12, 13, 333, 15, 16, 17, 434, 22, 23, 24, 535, 5, 6, 7, 636, 26, 27, 28, 737, 9]
        ,
        [131, 1, 2, 3, 232, 11, 12, 13, 333, 15, 16, 17, 434, 22, 23, 24, 535, 5, 6, 7, 636, 26, 27, 28, 737, 9, 19]
        ,
    ]

    t填充难度(nmu) {
        if (nmu == 0) { //教程关卡
            this.z总填充组 = [131, 131, 131, 11, 12, 13, 5, 5, 5]
            this.g关卡总数 += this.z总填充组.length
            this.k开始填充()
        } else {
            //计算地图总长度-zcd
            let zcd = 0
            this.cs层数据组.forEach((c) => {
                c.forEach((n) => {
                    if (n == 0) {
                        zcd++
                    }
                })
            })

            if (this.b必看广告关卡) {
                zcd -= 18
            }

            let z增加数 = 14

            let nds = this.HC_MLGM_chuangguangshu - 1       //每过一关难度加1
            if (nds == 1) {
                z增加数 = 0
            }

            if (nds > this.n难度类型.length - 1) {
                nds = this.ty.Rand(4, 6)     //最高后随机4到6难度
            }

            this.z总填充组 = []
            this.t填充类型 = Array.from(this.n难度类型[nds])


            //生成需要填充的总数组
            let cd = 0
            for (let k = 0; k < 1000; k++) {
                for (let i = 0; i < this.t填充类型.length; i++) {
                    for (let j = 0; j < 3; j++) {
                        this.z总填充组.push(this.t填充类型[i])
                        cd++
                    }
                    if (cd > zcd + z增加数) {   //超过总长度+14停止  //15为极限
                        break
                    }
                }
                if (cd > zcd + z增加数) {
                    break
                }
            }

            this.ty.s随机打乱(this.z总填充组)

            if (this.b必看广告关卡) {
                let a = this.s设计比不能过关卡填充()
                a.forEach((e) => {
                    this.z总填充组.unshift(e)
                })

            }

            this.g关卡总数 += this.z总填充组.length
            log(this.t填充类型)
            this.k开始填充()

        }

    }

    s设计比不能过关卡填充() {

        let a1 = [19, 737, 26, 7, 5, 9]
        this.ty.s随机打乱(a1)

        let t填充 = [a1[0], a1[1], a1[2], a1[3], a1[4], a1[5], a1[0], a1[0], a1[1], a1[1], a1[2], a1[2], a1[3], a1[3], a1[4], a1[4], a1[5], a1[5]]

        return t填充
    }


    k开始填充() {
        //填充层数
        let z总填daihao = 0

        for (let c = 0; c < this.cs层数据组.length; c++) {  //c为层数
            for (let dh = 0; dh < this.cs层数据组[c].length; dh++) {   //i为代号数
                if (this.cs层数据组[c][dh] == 0) {
                    let shuzhi = this.z总填充组[z总填daihao]
                    this.cs层数据组[c][dh] = shuzhi
                    this.s生成更新麻将造型位置1(dh, c, shuzhi)

                    z总填daihao++
                    if (z总填daihao >= this.z总填充组.length) {
                        break
                    }
                }
            }
            if (z总填daihao >= this.z总填充组.length) {
                break
            }
        }


        if (z总填daihao < this.z总填充组.length) {
            for (let cihao = z总填daihao; cihao < this.z总填充组.length; cihao++) {   //daihao为当前组接着剩下
                let f = () => {
                    let czd = this.x小层节点组.length - 1   //czd为层数
                    if (this.x小层节点组[czd][0] == null) {
                        let shuzhi = this.z总填充组[cihao]
                        this.s属性 = {
                            s数值: shuzhi,
                            c层数: czd,
                            代号: -1,
                            k可点击: 1
                        }
                        let n = instantiate(this.z子牌)
                        n.setParent(this.p牌组)
                        n.setPosition(this.z左组初始x + czd * this.j间隔距离小, this.z左组初始y)

                        n.name = JSON.stringify(this.s属性)
                        n.on(Node.EventType.TOUCH_START, this.点击执行1, this)
                        n.children[0].getChildByName(shuzhi + '').active = true//更新造型 

                        this.x小层节点组[czd][0] = n

                        //测试用
                        if (this.c测试中) {
                            this.ty.x修改文字(n.children[0].getChildByName('Label'), czd + '')
                        }


                    } else if (this.x小层节点组[czd][1] == null) {
                        let shuzhi = this.z总填充组[cihao]
                        this.s属性 = {
                            s数值: shuzhi,
                            c层数: czd,
                            代号: -2,
                            k可点击: 0
                        }
                        let n = instantiate(this.z子牌)
                        n.setParent(this.p牌组)
                        n.setPosition(-this.z左组初始x - czd * this.j间隔距离小, this.z左组初始y)

                        n.name = JSON.stringify(this.s属性)
                        n.on(Node.EventType.TOUCH_START, this.点击执行1, this)
                        n.children[0].getChildByName(shuzhi + '').active = true//更新造型 

                        this.x小层节点组[czd][1] = n

                        //测试用
                        if (this.c测试中) {
                            this.ty.x修改文字(n.children[0].getChildByName('Label'), czd + '')
                        }

                    } else {
                        let lssz: Node[] = [null, null]
                        this.x小层节点组.push(lssz)
                        f()
                    }
                }
                f()
            }
        }

        this.g更新麻将可点击显示()
    }



    x修改进度显示() {
        let jst = find('Canvas/上方显示组/进度/底板/遮罩/jdt')
        let shaizi = find('Canvas/上方显示组/进度/底板/筛子位置/sz')

        let x = -350 + (this.d当前消除数 / this.g关卡总数 * 700)
        if (x >= 350) {
            x = 350
        }
        tween(jst).to(0.3, { position: v3(x, 0) }).start()
        tween(shaizi).to(0.3, { position: v3(x, 0) })
            .call(() => {
                let ns = this.ty.find查找('Canvas/上方显示组/进度/yuanhuawen/Label')
                let wz = this.g关卡总数 - this.d当前消除数 + ''
                this.ty.x修改文字(ns, wz)
            })
            .start()


    }


    s生成更新麻将造型位置1(daihao, cenghao, shuzhi) {
        let hlh = this.ty.z转行列号(daihao, this.z总列数)
        let n = instantiate(this.z子牌)
        n.setParent(this.p牌组)
        this.ty.s设置位置(n, hlh.l, hlh.h, this.c初始x, this.c初始y, this.j间隔距离x, this.j间隔距离y)
        this.s属性 = {
            s数值: shuzhi,
            c层数: cenghao,
            代号: daihao,
            k可点击: 1
        }

        n.name = JSON.stringify(this.s属性)
        n.on(Node.EventType.TOUCH_START, this.点击执行1, this)

        n.children[0].getChildByName(shuzhi + '').active = true//更新造型 

        this.cs层节点组[cenghao][daihao] = n

        if (this.c测试中) {
            this.ty.x修改文字(n.children[0].getChildByName('Label'), cenghao + '')
        }
    }
    k可点击 = true
    点击执行1(e: EventTouch) {
        if (this.k可点击) {
            let n: Node = e.target
            let na: s属性face = JSON.parse(n.name)

            if (na.k可点击 == 1) {
                this.ty.bofangshenyin(28)
                //删除程序
                if (na.代号 >= 0) {
                    this.cs层节点组[na.c层数][na.代号] = null

                    this.y移动程序(n)
                } else if (na.代号 < 0) {
                    let xdh = -1
                    if (na.代号 == -1) {
                        xdh = 0
                    }
                    if (na.代号 == -2) {
                        xdh = 1
                    }

                    this.x小层节点组[na.c层数][xdh] = null
                    this.y移动程序(n)

                } else {
                    console.warn('出错了')
                }

                if (this.j教学中) {
                    this.j教学中 = false
                    let szn = this.ty.find查找('Canvas/教学组/shouzhi1')
                    Tween.stopAllByTarget(szn)
                    szn.setPosition(5000, 5000)
                }

                this.d当前消除数++
                this.x修改进度显示()

                this.g更新麻将可点击显示()

            }
        }
    }


    y移动程序(n: Node) {


        let h_length = this.h盒子节点.length
        if (h_length < this.h盒子总数) {    //用来判断是否广告开了格子
            let weizhi = 0
            for (let i = 0; i < this.h盒子总数; i++) {
                if (this.h盒子节点[i] == null) {
                    weizhi = i
                    break
                }
            }

            this.h盒子节点.splice(weizhi, 0, n)
            n.setParent(this.ty.find查找('Canvas/格子组'))
            //改名字
            let na: s属性face = JSON.parse(n.name)
            this.s属性 = na
            this.s属性.k可点击 = 0
            n.name = JSON.stringify(this.s属性)

            this.g更新位置()

        }
    }

    DH_yidong: any[] = []
    g更新位置() {

        this.h盒子节点.sort((a, b) => JSON.parse(a.name).s数值 - JSON.parse(b.name).s数值)

        let daihao = 0
        let cx = -263
        let cy = -438
        let jiange = 75
        for (let n of this.h盒子节点) {
            let v = v3(cx + daihao * jiange, cy)
            this.DH_yidong.push(n)
            tween(n)
                .to(0.3, { position: v })
                .call(() => {
                    let dhs = this.DH_yidong.indexOf(n)
                    this.DH_yidong.splice(dhs, 1)
                    if (this.DH_yidong.length == 0) {   //最后一个执行1次

                    }
                })
                .start()
            daihao++
        }
        this.p判断删除()
    }


    p判断删除() {
        let k碰 = false
        let k吃 = false
        let weizhi = 0
        if (this.h盒子节点.length != 0) {
            for (let i = 0; i < this.h盒子节点.length; i++) {
                let nam: s属性face = JSON.parse(this.h盒子节点[i].name)
                let nshuzhi = nam.s数值
                let shuliang = 0
                for (let nn of this.h盒子节点) {
                    let nam2: s属性face = JSON.parse(nn.name)
                    let nshuzhi2 = nam2.s数值
                    if (nshuzhi == nshuzhi2) {
                        shuliang++
                        if (shuliang >= 3) {
                            weizhi = i
                            k碰 = true
                            break
                        }
                    }
                }
                if (shuliang >= 3) {
                    weizhi = i
                    k碰 = true
                    break
                }
            }
        }

        let chisz: number[] = []
        if (!k碰) {
            if (this.h盒子节点.length != 0) {
                let lssc: number[] = []
                this.h盒子节点.forEach((n: Node) => {
                    lssc.push(JSON.parse(n.name).s数值)
                })
                if (this.ty.p判断连续的数字位置(lssc).w位置[0]) {
                    chisz = this.ty.p判断连续的数字位置(lssc).w位置[0]
                    if (chisz.length > 0) {
                        k吃 = true
                    }
                }
            }
        }


        if (k碰 || k吃) {

            let sz: Node[] = []
            if (k碰) {
                sz.push(this.h盒子节点[weizhi])
                sz.push(this.h盒子节点[weizhi + 1])
                sz.push(this.h盒子节点[weizhi + 2])
            }
            if (k吃) {
                sz.push(this.h盒子节点[chisz[0]])
                sz.push(this.h盒子节点[chisz[1]])
                sz.push(this.h盒子节点[chisz[2]])
            }


            let cishu = 0
            for (let n of sz) {
                let daihao = this.h盒子节点.indexOf(n)  //删除节点所在数组位置
                this.h盒子节点.splice(daihao, 1)


                //删除动画
                let f = () => {
                    let p = sz[0].worldPosition.clone()
                    tween(n).to(0.3, { worldPosition: p })
                        .call(() => {
                            cishu++
                            if (cishu == 1) {
                                let dh = this.ty.find查找('Canvas/动画组/炸开')
                                dh.setWorldPosition(p)
                                this.ty.b播放粒子(dh)
                                this.ty.bofangshenyin(15)
                                if (k碰) {
                                    this.p碰动画()
                                }
                                if (k吃) {
                                    this.c吃动画()
                                }
                                this.g更新位置()

                                let pz = this.ty.find查找('Canvas/牌组')
                                if (pz.children.length == 0) {
                                    this.s胜利执行()
                                }

                            }
                            n.destroy()
                        })
                        .start()
                }

                this.scheduleOnce(f, 0.3)

            }



        } else {
            if (this.c测试中) {
                let n = this.h盒子节点[0]
                this.h盒子节点.splice(0, 1)
                n.destroy()
            }

            if (this.h盒子节点.length == this.h盒子总数) {
                this.k可点击 = false
                this.scheduleOnce(this.s失败执行, 0.4)
            }
        }
    }

    q圈动画() {
        let n1 = this.ty.find查找('Canvas/动画组/圈/dongquan1')
        let n2 = this.ty.find查找('Canvas/动画组/圈/dongquan2')
        n1.setPosition(0, 0)
        n2.setPosition(0, 0)
        n2.angle = -250
        tween(n2).to(0.3, { angle: 0 })
            .call(() => {
                n1.setPosition(0, 5000)
                n2.setPosition(0, 5000)
            })
            .start()
    }

    p碰动画() {
        this.ty.z震动执行()
        this.ty.bofangshenyin(29)
        let n = find('Canvas/动画组/碰')
        n.setPosition(0, 260)
        n.setScale(0.5, 0.5)
        Tween.stopAllByTarget(n)
        tween(n).to(0.2, { position: v3(0, 0) }).start()
        tween(n).to(0.2, { scale: v3(1, 1) })
            .call(() => {
                let zi = find('Canvas/动画组/星星飞舞')
                zi.setPosition(0, 0)
                this.ty.b播放粒子(zi)
                this.q圈动画()
            })
            .delay(1)
            .set({ position: v3(2000, 0) })
            .start()

        this.l连击执行()
    }

    c吃动画() {
        this.ty.z震动执行()
        this.ty.bofangshenyin(31)
        let n = find('Canvas/动画组/吃')
        n.setPosition(0, 260)
        n.setScale(0.5, 0.5, 1)
        Tween.stopAllByTarget(n)
        tween(n).to(0.2, { position: v3(0, 0) }).start()
        tween(n).to(0.2, { scale: v3(1, 1, 1) })
            .call(() => {
                let zi = find('Canvas/动画组/星星飞舞')
                zi.setPosition(0, 0)
                this.ty.b播放粒子(zi)
                this.q圈动画()
            })
            .delay(1)
            .set({ position: v3(2000, 0) })
            .start()

        this.l连击执行()
    }

    b爆炸动画() {
        this.ty.z震动执行()
        let n = find('Canvas/动画组/爆炸')
        n.getComponent(Animation).play()
    }

    l连击执行() {

    }

    g更新麻将可点击显示() {
        //更新大组的显示
        //遍历全部当前麻将
        this.cs层节点组.forEach((c) => {
            c.forEach((n: Node) => {
                if (n) {
                    this.b变亮程序(n)
                }
            })
        })

        for (let ceng = this.cs层节点组.length - 1; ceng >= 0; ceng--) {
            this.cs层节点组[ceng].forEach((e: Node) => {
                if (e) {
                    let sx: s属性face = JSON.parse(e.name)
                    let daihao = sx.代号
                    let hlh = this.ty.z转行列号(daihao, this.z总列数)
                    for (let xhc = ceng - 1; xhc >= 0; xhc--) {
                        if (xhc >= 0) {
                            let zcsz = this.cs层节点组[xhc]
                            let f = (hhh, lll) => {
                                if (zcsz[this.ty.z转代号(hhh, lll, this.z总列数)] != null) {
                                    let n = zcsz[this.ty.z转代号(hhh, lll, this.z总列数)]
                                    this.b变暗程序(n)
                                }
                            }
                            //判断当前
                            let hh = hlh.h
                            let lh = hlh.l
                            f(hh, lh)

                            //判断左
                            if (lh - 1 >= 0) {
                                f(hh, lh - 1)
                            }
                            //判断右
                            if (lh + 1 < this.z总列数) {
                                f(hh, lh + 1)
                            }
                            //判断上
                            if (hh + 1 < this.z总行数) {
                                f(hh + 1, lh)
                            }
                            //判断下
                            if (hh - 1 >= 0) {
                                f(hh - 1, lh)
                            }
                            //判断左上
                            if (hh + 1 < this.z总行数 && lh - 1 >= 0) {
                                f(hh + 1, lh - 1)
                            }
                            //判断右上
                            if (hh + 1 < this.z总行数 && lh + 1 < this.z总列数) {
                                f(hh + 1, lh + 1)
                            }
                            //判断左下
                            if (lh - 1 >= 0 && hh - 1 >= 0) {
                                f(hh - 1, lh - 1)
                            }
                            //判断右下
                            if (lh + 1 < this.z总列数 && hh - 1 >= 0) {
                                f(hh - 1, lh + 1)
                            }
                        }

                    }

                }
            })
        }

        //小组的显示
        //遍历全部当前麻将
        //遍历全部当前麻将
        if (this.x小层节点组.length > 0) {
            this.x小层节点组.forEach((c) => {
                c.forEach((n: Node) => {
                    if (n) {
                        this.b变暗程序(n)
                    }
                })
            })
            let sz1: Node[] = []
            let sz2: Node[] = []
            this.x小层节点组.forEach((c) => {
                sz1.push(c[0])
                sz2.push(c[1])
            })

            for (let weiz = sz1.length - 1; weiz >= 0; weiz--) {
                if (sz1[weiz]) {
                    this.b变亮程序(sz1[weiz])
                    break
                }
            }
            for (let weiz = sz2.length - 1; weiz >= 0; weiz--) {
                if (sz2[weiz]) {
                    this.b变亮程序(sz2[weiz])
                    break
                }
            }

        }
    }

    b变暗程序(n: Node) {
        let na: s属性face = JSON.parse(n.name)
        this.s属性 = na
        this.s属性.k可点击 = 0
        n.name = JSON.stringify(this.s属性)
        this.ty.x修改透明度(n.children[1], 200)
    }

    b变亮程序(n: Node) {
        let na: s属性face = JSON.parse(n.name)
        this.s属性 = na
        this.s属性.k可点击 = 1
        n.name = JSON.stringify(this.s属性)
        this.ty.x修改透明度(n.children[1], 0)
    }


    复活次数 = 1
    s失败执行() {
        this.ty.c创建banner(2)
        let nnf1 = this.ty.find查找('Canvas/弹出主/满格失败/小组/按钮1组/按钮_复活满格')
        let nnf2 = this.ty.find查找('Canvas/弹出主/满格失败/小组/按钮1组/按钮_复活时间')
        nnf1.setPosition(140, -200)
        nnf2.setPosition(140, 5000)

        let wznn = this.ty.find查找("Canvas/弹出主/满格失败/小组/lab")
        this.ty.c持续缩放(wznn)
        let wzw = '没有位置了'
        this.ty.x修改文字(wznn, wzw)
        this.ty.bofangshenyin(12)
        let xn = this.ty.find查找("Canvas/弹出主/满格失败/小组/款背景/xinsui")
        this.ty.c持续旋转(xn, 8, 0.3)

        let n = find('Canvas/弹出主/满格失败')
        this.ty.t弹出通用(n)

        if (this.复活次数 > 0) {
            let tsn = this.ty.find查找('Canvas/弹出主/满格失败/小组/huawen1/提示文字')
            let wz = '复活（仅一次机会）'
            this.ty.x修改文字(tsn, wz)

            let nan1 = this.ty.find查找('Canvas/弹出主/满格失败/小组/按钮1组')
            let nan2 = this.ty.find查找('Canvas/弹出主/满格失败/小组/按钮2组')
            nan2.setPosition(0, 5000)
            nan1.setPosition(0, 0)
        } else {
            let tsn = this.ty.find查找('Canvas/弹出主/满格失败/小组/huawen1/提示文字')
            let wz = '胜败乃兵家常事！'
            this.ty.x修改文字(tsn, wz)

            let nan1 = this.ty.find查找('Canvas/弹出主/满格失败/小组/按钮1组')
            let nan2 = this.ty.find查找('Canvas/弹出主/满格失败/小组/按钮2组')

            nan1.setPosition(0, 5000)
            nan2.setPosition(0, 0)
        }
    }

    放弃复活() {
        this.ty.bofangshenyin(1)
        let nan1 = this.ty.find查找('Canvas/弹出主/满格失败/小组/按钮1组')
        let nan2 = this.ty.find查找('Canvas/弹出主/满格失败/小组/按钮2组')

        let tsn = this.ty.find查找('Canvas/弹出主/满格失败/小组/huawen1/提示文字')
        let wz = '胜败乃兵家常事！'
        this.ty.x修改文字(tsn, wz)
        nan1.setPosition(0, 5000)
        nan2.setPosition(0, 0)
    }


    f满格复活() {
        this.k可点击 = true
        this.ty.g关闭banner()
        let f = () => {
            let n = find('Canvas/弹出主/满格失败')
            this.ty.g关闭通用(n)
            this.复活次数 = 0

            //复活程序
            let vz = [v3(-75, -310), v3(0, -310), v3(75, -310)]
            let pzn = this.ty.find查找('Canvas/牌组')

            for (let j = 0; j < 3; j++) {
                let b = false

                let sls: Node[] = [

                ]
                this.h盒子节点.forEach((n) => {
                    sls.push(n)
                })
                for (let i = 0; i < 3; i++) {
                    if (sls.length - 1 - i < 0) {
                        b = true
                        break
                    }
                    let daihao = sls.length - 1 - i  //删除节点所在数组位置
                    let n = this.h盒子节点[daihao]
                    this.h盒子节点.splice(daihao, 1)
                    n.setParent(pzn)

                    this.d当前消除数--
                    this.x修改进度显示()

                    //改名字属性
                    let nams: s属性face = JSON.parse(n.name)
                    this.s属性 = nams
                    this.s属性.k可点击 = 1
                    n.name = JSON.stringify(this.s属性)

                    let v = vz[i]
                    tween(n).to(0.3, { position: v }).start()
                }

                if (b) {
                    break
                }
            }

        }
        this.ty.c创建激励广告(f)

    }

    k胜利 = true
    s胜利执行() {
        if (this.k胜利) {
            this.ty.c创建banner(2)
            this.k胜利 = false
            this.ty.bofangshenyin(14)
            let n = this.ty.find查找('Canvas/弹出主/胜利弹出')
            this.ty.t弹出通用(n)

            this.奖励金币动画与执行()
        }
    }

    b倍率 = 1
    奖励金币动画与执行() {
        let cdlz = this.ty.find查找('Canvas/动画组/彩带')
        this.ty.b播放粒子(cdlz)

        let jbs = this.g过关奖励金币
        let wzn = find('Canvas/弹出主/胜利弹出/小组/领取窗口/jingbi普通/数量文字')
        this.ty.x修改文字(wzn, 'x' + jbs)

        let shaizi = find('Canvas/弹出主/胜利弹出/小组/领取窗口/shaizixiao')
        Tween.stopAllByTarget(shaizi)
        shaizi.setPosition(-200, 40)
        let t = tween(shaizi).to(0.6, { position: v3(200, 40) }).to(0.6, { position: v3(-200, 40) })
        tween(shaizi).repeatForever(t).start()
        let dnz = find('Canvas/弹出主/胜利弹出/小组/领取窗口/jingbi多倍/数量文字')
        let f = () => {
            this.ty.x修改文字(dnz, "x" + jbs * this.b倍率)
        }
        let t2 = tween(dnz)
            .call(() => {
                this.b倍率 = 2
                f()
            })
            .delay(0.1)
            .call(() => {
                this.b倍率 = 3
                f()
            })
            .delay(0.1)
            .call(() => {
                this.b倍率 = 4
                f()
            })
            .delay(0.1)
            .call(() => {
                this.b倍率 = 5
                f()
            })
            .delay(0.1)
            .call(() => {
                this.b倍率 = 4
                f()
            })
            .delay(0.1)
            .call(() => {
                this.b倍率 = 3
                f()
            })
            .delay(0.1)
            .call(() => {
                this.b倍率 = 2
                f()
            })

        Tween.stopAllByTarget(dnz)
        tween(dnz).repeatForever(t2).start()
    }

    P普通领取() {
        this.ty.bofangshenyin(13)
        let jblz = this.ty.find查找('Canvas/动画组/掉金币')
        this.ty.b播放粒子(jblz)

        let wzn = this.ty.find查找('Canvas/上方显示组/金币显示/修改文字')
        let zzsz = this.HC_qian + this.g过关奖励金币
        let dx = {
            num: this.HC_qian
        }
        this.ty.d动态修改数值(dx, wzn, 5, zzsz)

        this.HC_qian += this.g过关奖励金币
        localStorage.setItem('HC_qian', JSON.stringify(this.HC_qian))



        let lck = this.ty.find查找('Canvas/弹出主/胜利弹出/小组/领取窗口')
        lck.setPosition(5000, 5000)

        let xgck = this.ty.find查找('Canvas/弹出主/胜利弹出/小组/下一关窗口')
        xgck.setPosition(0, 0)

        let jbtb = this.ty.find查找('Canvas/弹出主/胜利弹出/金币图标')
        this.ty.x修改透明度(jbtb, 255)
        this.ty.d抖动(jbtb)
    }


    d多倍领取() {
        let f = () => {
            this.ty.bofangshenyin(13)
            let jblz = this.ty.find查找('Canvas/动画组/掉金币')
            this.ty.b播放粒子(jblz)

            let wzn = this.ty.find查找('Canvas/上方显示组/金币显示/修改文字')
            let zzsz = this.HC_qian + this.g过关奖励金币 * this.b倍率
            let dx = {
                num: this.HC_qian
            }
            this.ty.d动态修改数值(dx, wzn, 5, zzsz)

            this.HC_qian += this.g过关奖励金币 * this.b倍率
            localStorage.setItem('HC_qian', JSON.stringify(this.HC_qian))

            let lck = this.ty.find查找('Canvas/弹出主/胜利弹出/小组/领取窗口')
            lck.setPosition(5000, 5000)

            let xgck = this.ty.find查找('Canvas/弹出主/胜利弹出/小组/下一关窗口')
            xgck.setPosition(0, 0)

            let jbtb = this.ty.find查找('Canvas/弹出主/胜利弹出/金币图标')
            this.ty.x修改透明度(jbtb, 255)
            this.ty.d抖动(jbtb)
        }
        this.ty.c创建激励广告(f)

    }


    k可点x = true
    x下一关点击() {
        if (this.k可点x) {
            this.ty.c创建插屏()
            this.k可点x = false
            this.ty.bofangshenyin(1)
            this.HC_MLGM_chuangguangshu++
            localStorage.setItem('HC_MLGM_chuangguangshu', JSON.stringify(this.HC_MLGM_chuangguangshu));

            Tween.stopAll()
            director.loadScene('malegema')
        }

    }

    //UI
    设置点击() {
        this.ty.c创建banner(2)
        this.ty.bofangshenyin(1)
        let n = find('Canvas/弹出主/设置弹出')
        this.ty.t弹出通用(n)
    }

    设置关闭() {
        this.ty.g关闭banner()
        this.ty.bofangshenyin(1)
        let n = find('Canvas/弹出主/设置弹出')
        this.ty.g关闭通用(n)
    }

    t退出() {
        this.ty.c创建插屏()
        this.ty.bofangshenyin(1)
        Tween.stopAll()
        director.loadScene('kaishichangjing')
    }


    //道具
    s刷新执行() {
        let f = () => {
            if (this.d道具只能使用一次) {
                let djan = this.ty.find查找('Canvas/道具组/道具_刷新')
                djan.setPosition(5000, 5000)
            }


            this.g关闭提示()
            this.ty.bofangshenyin(33)
            let n = this.ty.find查找('Canvas/牌组')
            let lssz = []
            n.children.forEach((n) => {
                let sx: s属性face = JSON.parse(n.name)
                let sz = sx.s数值
                lssz.push(sz)
            })
            this.ty.s随机打乱(lssz)

            let daihao = 0
            lssz.forEach((sz) => {
                let nams: s属性face = JSON.parse(n.children[daihao].name)
                this.s属性 = nams
                this.s属性.s数值 = sz
                n.children[daihao].name = JSON.stringify(this.s属性)



                //更新造型
                n.children[daihao].children[0].children.forEach((n) => {
                    n.active = false
                })
                n.children[daihao].children[0].getChildByName(sz + '').active = true//更新造型 

                this.ty.f反转(n.children[daihao])
                daihao++
            })
        }
        this.ty.c创建激励广告(f)

    }

    y移除执行() {
        let f = () => {
            if (this.d道具只能使用一次) {
                let djan = this.ty.find查找('Canvas/道具组/道具_消除')
                djan.setPosition(5000, 5000)
            }
            this.g关闭提示()
            this.ty.bofangshenyin(24)
            let vz = [v3(-75, -310), v3(0, -310), v3(75, -310)]
            let pzn = this.ty.find查找('Canvas/牌组')
            let sls: Node[] = [

            ]
            this.h盒子节点.forEach((n) => {
                sls.push(n)
            })
            for (let i = 0; i < 3; i++) {
                if (sls.length - 1 - i < 0) {
                    break
                }
                let daihao = sls.length - 1 - i  //删除节点所在数组位置
                let n = this.h盒子节点[daihao]
                this.h盒子节点.splice(daihao, 1)
                n.setParent(pzn)

                this.d当前消除数--
                this.x修改进度显示()

                //改名字属性
                let nams: s属性face = JSON.parse(n.name)
                this.s属性 = nams
                this.s属性.k可点击 = 1
                n.name = JSON.stringify(this.s属性)

                let v = vz[i]
                tween(n).to(0.3, { position: v }).start()
            }
        }
        this.ty.c创建激励广告(f)

    }

    z炸花牌执行() {
        this.ty.g关闭banner()
        let f = () => {
            if (this.d道具只能使用一次) {
                let djan = this.ty.find查找('Canvas/道具组/道具_炸弹')
                djan.setPosition(5000, 5000)
            }
            let zzzn = this.ty.find查找('Canvas/总遮罩')
            zzzn.setPosition(0, 0)

            let n = this.ty.find查找('Canvas/牌组')
            let lssz: Node[] = []
            n.children.forEach((n) => {
                let sx: s属性face = JSON.parse(n.name)
                let sz = sx.s数值
                if (sz > 100) {
                    lssz.push(n)
                }
            })

            lssz.forEach((n) => {
                let ssxx: s属性face = JSON.parse(n.name)
                let c = ssxx.c层数
                let dai = ssxx.代号
                if (dai >= 0) {
                    this.cs层节点组[c][dai] = null
                } else {
                    let daih = -dai - 1
                    this.x小层节点组[c][daih] = null
                }
                this.d当前消除数++

                n.setParent(this.ty.find查找('Canvas/销毁组'))
                tween(n).to(0.5, { position: v3(0, 0) }).call(() => {
                    n.destroy()
                }).start()
            })

            let lssz2: Node[] = []
            this.h盒子节点.forEach((n) => {
                let sx: s属性face = JSON.parse(n.name)
                let sz = sx.s数值
                if (sz > 100) {
                    lssz2.push(n)
                }
            })

            lssz2.forEach((n) => {
                //删除所在h盒子节点所在位置
                let daihao = this.h盒子节点.indexOf(n)
                this.h盒子节点.splice(daihao, 1)


                n.setParent(this.ty.find查找('Canvas/销毁组'))
                tween(n).to(0.5, { position: v3(0, 0) }).call(() => {
                    n.destroy()
                }).start()
            })

            let ycf = () => {
                this.ty.bofangshenyin(11)
                zzzn.setPosition(5000, 5000)
                this.b爆炸动画()
                this.g更新麻将可点击显示()
                this.x修改进度显示()

                let pz = this.ty.find查找('Canvas/牌组')
                if (pz.children.length == 0) {
                    this.s胜利执行()
                }
            }
            this.scheduleOnce(ycf, 0.5)
        }
        this.ty.c创建激励广告(f)

    }


    j加格子执行() {
        let f = () => {
            this.g关闭提示()
            if (this.h盒子总数 == 6) {
                let n = this.ty.find查找('Canvas/弹出主/广告提示弹出')
                n.setPosition(-2000, 0)
                n = this.ty.find查找('Canvas/道具组/解锁组/解锁按钮1')
                n.setPosition(5000, 5000)

                this.h盒子总数 = 7
            } else {
                if (this.h盒子总数 == 7) {
                    let n = this.ty.find查找('Canvas/弹出主/广告提示弹出')
                    n.setPosition(-2000, 0)
                    n = this.ty.find查找('Canvas/道具组/解锁组/解锁按钮2')
                    n.setPosition(5000, 5000)
                    this.h盒子总数 = 8
                }
            }
        }
        this.ty.c创建激励广告(f)

    }



    d道具点击(d, e) {
        this.ty.c创建banner(2)
        this.ty.bofangshenyin(1)
        let n = this.ty.find查找('Canvas/弹出主/广告提示弹出')
        this.ty.t弹出通用(n)

        let tn = this.ty.find查找('Canvas/弹出主/广告提示弹出/小组/图标组')
        tn.children.forEach((n) => {
            n.setPosition(5000, 5000)
        })

        let lqan = this.ty.find查找('Canvas/弹出主/广告提示弹出/小组/领取组/按钮_领取')
        if (e == 0) {
            this.ty.x修改Button参数(lqan, e + '')
            tn.children[e].setPosition(0, 0)
            if (this.d点击直接展示广告) {
                this.j加格子执行()
            }
        }
        if (e == 1) {
            this.ty.x修改Button参数(lqan, e + '')
            tn.children[e].setPosition(0, 0)
            if (this.d点击直接展示广告) {
                this.s刷新执行()
            }
        }
        if (e == 2) {
            this.ty.x修改Button参数(lqan, e + '')
            tn.children[e].setPosition(0, 0)
            if (this.d点击直接展示广告) {
                this.y移除执行()
            }
        }

    }

    g关闭提示() {
        this.ty.g关闭banner()
        let n = this.ty.find查找('Canvas/弹出主/广告提示弹出')
        this.ty.g关闭通用(n)
    }

    AN_领取(e, env) {
        if (env == 0) {
            this.j加格子执行()
        }
        if (env == 1) {
            this.s刷新执行()
        }
        if (env == 2) {
            this.y移除执行()
        }
    }


    z炸弹点击() {
        this.ty.c创建banner(2)
        this.ty.bofangshenyin(1)
        //炸弹提示弹出
        let n = this.ty.find查找('Canvas/弹出主/炸弹使用提示弹出')
        this.ty.t弹出通用(n)
    }



    z炸弹购买() {
        this.ty.g关闭banner()
        if (this.HC_qian >= 800) {
            this.ty.bofangshenyin(1)
            this.HC_qian -= 800
            localStorage.setItem('HC_qian', JSON.stringify(this.HC_qian));

            let wzn = this.ty.find查找('Canvas/上方显示组/金币显示/修改文字')
            let wz = this.HC_qian + ''
            this.ty.x修改文字(wzn, wz)

            let n = this.ty.find查找('Canvas/弹出主/炸弹使用提示弹出')
            this.ty.g关闭通用(n)

            this.z炸花牌执行()
        } else {
            this.ty.bofangshenyin(4)
            let tn = this.ty.find查找('Canvas/动画组/对话框')
            let v = v3(0, 0, 0)
            let wn = this.ty.find查找('Canvas/动画组/对话框/Label')
            let wz = '金币不足'
            this.ty.t提示(tn, v, wn, wz)

            let jn = this.ty.find查找('Canvas/上方显示组/金币显示/修改文字')
            this.ty.d抖动(jn)

            let n = this.ty.find查找('Canvas/弹出主/炸弹使用提示弹出')
            this.ty.g关闭通用(n)
        }
    }

    z炸弹放弃() {
        this.ty.g关闭banner()
        this.ty.bofangshenyin(1)
        let n = this.ty.find查找('Canvas/弹出主/炸弹使用提示弹出')
        this.ty.g关闭通用(n)
    }


}


